%option noyywrap
%option yylineno

%x COMMENT

%{
#include <string>
#include <list>
#include "library/node.h"
#include "parser.hpp"
#define  CAPTURE(TYPE, TOKEN) yylval.TYPE = new std::string(yytext); return TOKEN;
%}

FLOAT   (0|[1-9][0-9]*)\.[0-9]+
INTEGER ((0|[1-9][0-9]*)|0x[0-9A-F]+)
ID      [_a-zA-Z][_a-zA-Z0-9]*
LITERAL \"(\\.|[^"])*\"

%%

<INITIAL>"/*" { BEGIN COMMENT; }
<COMMENT>.
<COMMENT>\n
<COMMENT>"*/" { BEGIN INITIAL; }

[ \t\n]
"int"     { CAPTURE(text, T_INT)        }
"float"   { CAPTURE(text, T_FLOAT)      }
"char"    { CAPTURE(text, T_CHAR)       }
"void"    { CAPTURE(text, T_VOID)       }
"new"     { return T_NEW;               }
"if"      { return T_IF;                }
"else"    { return T_ELSE;              }
"while"   { return T_WHILE;             }
"return"  { return T_RETURN;            }
"="       { return T_ASSIGN;            }
","       { return T_COMMA;             }
";"       { return T_SEMICOLON;         }
"=="      { CAPTURE(text, T_EQ)         }
"<="      { CAPTURE(text, T_LE)         }
">="      { CAPTURE(text, T_GE)         }
"<"       { CAPTURE(text, T_LT)         }
">"       { CAPTURE(text, T_GT)         }
"&&"      { CAPTURE(text, T_AND)        }
"||"      { CAPTURE(text, T_OR)         }
"("       { return T_OPB;               }
")"       { return T_CPB;               }
"["       { return T_OVB;               }
"]"       { return T_CVB;               }
"{"       { return T_OSB;               }
"}"       { return T_CSB;               }
"!"       { CAPTURE(text, T_NOT)        }
"-"       { CAPTURE(text, T_SUB)        }
"+"       { CAPTURE(text, T_ADD)        }
"*"       { CAPTURE(text, T_MUL)        }
"/"       { CAPTURE(text, T_DIV)        }
{FLOAT}   { CAPTURE(text, T_NFLOAT)     }
{INTEGER} { CAPTURE(text, T_NINTEGER)   }
{ID}      { CAPTURE(text, T_IDENTIFIER) }
.         { return T_UNKNOWN;           }

%%

